package com.kk.clone.deepClone;

import cn.hutool.core.util.ObjectUtil;

/**
 * the type of advance
 *
 * <p>
 * .
 *
 * @author 王志强
 * @date 2022-03-21
 */
public class SheepClient {
    public static void main(String[] args) {

        Sheep sheep = new Sheep("多利1号", 12);
        Sheep child = new Sheep("多利1号Child", 2);
        sheep.setSheep(child);

        // 实现深克隆
        Sheep cloneSheep = ObjectUtil.cloneByStream(sheep);
        // java对象地址值= 全类名 + "@" + （hashcode转为十六进制字符串）
        System.out.println("原对象：");
        System.out.println(sheep + " - " + sheep.getName() + " - " + sheep.getSheep());
        System.out.println(sheep.getSheep().getName());

        System.out.println("克隆对象：");
        System.out.println(cloneSheep + " - " + cloneSheep.getName() + " - " + cloneSheep.getSheep());
        System.out.println(cloneSheep.getSheep().getName());

        // 改变原对象属性后，深克隆对象的属性保持不变
        System.out.println("        \n// 改变原对象属性后，深克隆对象的属性保持不变");
        child.setName("多利3号");
        // java对象地址值= 全类名 + "@" + （hashcode转为十六进制字符串）
        System.out.println("原对象：");
        System.out.println(sheep + " - " + sheep.getName() + " - " + sheep.getSheep());
        System.out.println(sheep.getSheep().getName());

        System.out.println("克隆对象：");
        System.out.println(cloneSheep + " - " + cloneSheep.getName() + " - " + cloneSheep.getSheep());
        System.out.println(cloneSheep.getSheep().getName());

    }
}
